package com.ly.repository;

import com.ly.entity.House;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.security.spec.ECField;
import java.util.List;

/**
 * 使用PagingAndSortingRepository实现多维度排序
 *
 * 使用JpaSpecificationExecutor实现分页
 */
public interface HouseRepository  extends PagingAndSortingRepository<House,Long>, JpaSpecificationExecutor<House> {
   @Modifying
   @Query("update House as house set house.cover = :cover where house.id =:id")
    void updateCover(@Param(value = "id") Long id,@Param(value = "cover")  String cover);

   @Modifying
   @Query("update House as house set  house.status=:status where house.id =:id")
    void updateStatus(@Param(value = "id") Long id,@Param(value = "status") int status);
    @Modifying
    @Query("update House  as house set house.watchTimes = house.watchTimes+1 where house.id = :id ")
    void updateWatchTimes(@Param(value = "id")Long houseId);

    List<House> findAllByCityEnNameAndRegionEnName(String cityEnName, String regionEnName);

    @Query("select distinct house.regionEnName from House as house where house.district =:dit")
    String findAllRegionEnNameByDistrict(@Param(value = "dit")String district);
}
